import React, { useState } from 'react'
import { Button, Drawer, Tree } from "antd"
import {treeData} from "@/config/authData"
import {roleAuth} from "@/apis/role"

export default function Auth({roleId,menus,changeOpenModelState}) {
    const [open, setOpen] = useState(true);
    const [checkedTreeData,setCheckedTreeData] = useState(menus)
    const showDrawer = () => {
        setOpen(true);
    };
    const onClose = () => {
        changeOpenModelState()
    };
    const onCheck = (checkedKeys, info) => {
        console.log('onCheck', checkedKeys, info);
        setCheckedTreeData(checkedKeys)
    };

    const saveAuthData =async ()=>{
        const obj = {id:roleId,authTime:new Date(),authUser:"xiaowang",menus:checkedTreeData}
        const res = await roleAuth(obj)
        console.log(res);
    }
    return (
        <Drawer title="授权" placement="right" onClose={onClose} open={open}>
            <Tree
                checkable
                defaultExpandedKeys={["/home/product","/home/charts"]}
                defaultCheckedKeys={menus}
                onCheck={onCheck}
                treeData={treeData}
            />
            <Button onClick={saveAuthData}>保存</Button>

            <ul>
                <li>
                    123
                    <ul>
                        <li>233</li>
                    </ul>
                </li>
                <li>
                    1234
                </li>
            </ul>
        </Drawer>
    )
}
